package com.bamatea.reportfrom.service;

import com.bamatea.reportfrom.dao.BdInvclWcMapper;
import com.bamatea.reportfrom.domain.BdInvclWc;
import com.bamatea.reportfrom.domain.BdInvclWcExample;
import com.bamatea.reportfrom.domain.PoOrderBWc;
import com.bamatea.reportfrom.vo.CategoryVo;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Auther: libingbing
 * @Date: 2020-04-24 14 :26
 * @Description:
 */
@Service
public class BdinvclWcSercive {
    @Resource
    private BdInvclWcMapper mapper;

    public BdInvclWc findById(String invclasscode) {
        BdInvclWcExample example = new BdInvclWcExample();
        example.or().andInvclasscodeEqualTo(invclasscode);
        BdInvclWc bdInvclWc = mapper.selectOneByExample(example);
        return bdInvclWc;
    }

    public List<BdInvclWc> findAllCategory() {
        BdInvclWcExample example = new BdInvclWcExample();
        example.setDistinct(true);
        return mapper.selectByExampleSelective(example, BdInvclWc.Column.ordinarytype);
    }

    public List<BdInvclWc> findByName(String name){
        BdInvclWcExample example = new BdInvclWcExample();
        example.setDistinct(true);
        example.or().andOrdinarytypeEqualTo(name);
        return mapper.selectByExampleSelective(example,BdInvclWc.Column.invclasscode);
    }

    public List<CategoryVo> findAllCatClassCode() {
        BdInvclWcExample example = new BdInvclWcExample();
        List<BdInvclWc> list = mapper.selectByExample(example);
        List<CategoryVo> res = new ArrayList<>();
        for (BdInvclWc item : list) {
            String name = item.getInvclassname();
            String code = item.getInvclasscode();
            CategoryVo categoryVo = new CategoryVo();
            categoryVo.setInvClassCode(code);
            categoryVo.setInvClassName(name);
            res.add(categoryVo);
        }
        return res;
    }


    public List<BdInvclWc> findten() {
        BdInvclWcExample example = new BdInvclWcExample();
        PageHelper.startPage(2, 20);
        List<BdInvclWc> bdInvclWcs = mapper.selectByExample(example);
        return bdInvclWcs;
    }

    public List<BdInvclWc> findCategory() {
        BdInvclWcExample example = new BdInvclWcExample();
        example.setDistinct(true);
        return mapper.selectByExampleSelective(example, BdInvclWc.Column.invclasscode, BdInvclWc.Column.ordinarytype);
    }

    public List<BdInvclWc> findtea(){
        BdInvclWcExample example =new BdInvclWcExample();
        example.setDistinct(true);
        return mapper.selectByExampleSelective(example,BdInvclWc.Column.ordinarytype);


    }
}
